package com.openingedu.mba.screen.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lurencun.android.support.widget.CommonAdapter;
import com.openingedu.mba.R;
import com.openingedu.mba.persist.DbMessage;

public class MessageAdapter extends CommonAdapter<DbMessage>{

	private Context mContext;
	
	public MessageAdapter(Context context) {
		super(context);
		mContext = context;
	}

	@Override
	protected View createView(LayoutInflater inflater, final DbMessage data,
			int position, View convertView, ViewGroup parent) {
		LinearLayout messageLayout = (LinearLayout) inflater.inflate(R.layout.item_message, null);
		LinearLayout messageBox = (LinearLayout) messageLayout.findViewById(R.id.message_box);
		TextView contentView = (TextView) messageLayout.findViewById(R.id.message_content);
		TextView contentTime = (TextView) messageLayout.findViewById(R.id.message_time);
		Date createTime = data.getCreateTime();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
		contentView.setText(data.getContent());
		contentTime.setText(format.format(createTime));
		
		if (data.isRead()) {
			messageBox.setBackgroundResource(R.drawable.mail_box);
		}
		else {
			messageBox.setBackgroundResource(R.drawable.mail_box_new);
		}
		messageBox.setPadding(2, 2, 2, 2);
		return messageLayout;
	}
}
